package com.qf.listener;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainManager;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Zwnan
 */
@Component
public class RabbitMQListener {

    @Autowired
    private FilterChainManager filterChainManager;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = RabbitMQConstants.TOPIC_PRE_SEND,durable = "true",autoDelete = "false"),
            exchange = @Exchange(value = RabbitMQConstants.TOPIC_PRE_SEND+"_exchange",type = "topic"),
            key = "routingKey"
    ))
    public void receiverStandarSubmit(StandardSubmit standardSubmit, Message message, Channel channel){
        try {

            System.out.println(standardSubmit.getSequenceId());

            filterChainManager.executeFilter(standardSubmit);

            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);

        }catch (Exception e){

        }
    }
}
